using System;
using System.Collections.Generic;
using System.Linq;
namespace TTSoft.MyApp.Repositories
{
	#region using
	using TTSoft.MyApp.Models;
	#endregion
	public class PhieuMuonRepository
	{
		public static List<PhieuMuon> SelectAll()
		{
			return DataContext.Instance.PhieuMuon.ToList();
		}

		public static PhieuMuon SelectByID(int idphieumuon)
		{
			return DataContext.Instance.PhieuMuon.FirstOrDefault(item => item.IDPhieuMuon == idphieumuon );
		}

		public static bool Insert(PhieuMuon obj)
		{
			try
			{
				DataContext.Instance.PhieuMuon.AddObject(obj);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Delete(int idphieumuon)
		{
			try
			{
				var delitem = DataContext.Instance.PhieuMuon.FirstOrDefault(item => item.IDPhieuMuon == idphieumuon );
				DataContext.Instance.PhieuMuon.DeleteObject(delitem);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Save()
		{
			try
			{
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static List<PhieuMuon> RetrieveByID(int idphieumuon)
		{
			return (from item in DataContext.Instance.PhieuMuon where  item.IDPhieuMuon == idphieumuon  select item).ToList();
		}

		public static List<PhieuMuon> SelectByIDDocGia(int iddocgia)
		{
			var lstItem = (from item in DataContext.Instance.PhieuMuon where item.IDDocGia == iddocgia select item).ToList();
			return lstItem;
		}

	}
}